// 网络请求封装
const baseUrl = 'https://xpuw7sls.lc-cn-n1-shared.com'
export const $http = (url, method = 'GET', data = {}) => {
  return new Promise((resolve, reject) => {
    const isUser = data.isUser
    uni.request({
      url: baseUrl + url,
      method,
      data,
      header: {
        // 访问云服务需携带的请求头
        'X-LC-Id': 'xPuw7SLS5fwdBF4x9KW34Lh2-gzGzoHsz',
        'X-LC-Key': 'ikRfAGNBHeN5HeKxFnROFBzo',
        'Content-Type': 'application/json',
      },
      success: res => {
        if (!isUser) {
          if (res.statusCode === 200) return resolve(res.data)
          uni.showToast({
            title: '请求数据失败',
            duration: 2000,
            icon: 'none',
          })
        } else {
          resolve(res.data)
        }
      },
      fail: err => {
        reject(err)
      },
    })
  })
}

export const $get = (url, data = {}) => $http(url, 'GET', data)
export const $post = (url, data = {}) => $http(url, 'POST', data)
